package com.ebt.m.proposal_v2.widget.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.customer.constant.Dictionary;
import com.ebt.m.customer.view.ConfirmDialog;
import com.ebt.m.data.entity.Customer;
import com.ebt.m.proposal_v2.base.Constant;
import com.ebt.m.proposal_v2.bean.DateTime;
import com.ebt.m.proposal_v2.bean.InsuredEntity;
import com.ebt.m.proposal_v2.dao.response.BusinessConfig;
import com.ebt.m.proposal_v2.helper.PickerHelper;
import com.ebt.m.proposal_v2.ui.MakeProposalActivity;
import com.ebt.m.proposal_v2.ui.view.InsuranceView;
import com.ebt.m.proposal_v2.ui.view.InsuredView;
import com.ebt.m.proposal_v2.utils.ArrayUtils;
import com.ebt.m.proposal_v2.utils.DateUtils;
import com.ebt.m.proposal_v2.utils.InsuredCheckUtils;
import com.ebt.m.proposal_v2.utils.RxUtils;
import com.ebt.m.proposal_v2.utils.VerificationUtils;
import com.ebt.m.proposal_v2.widget.base.CompatLinearLayout;
import com.ebt.m.proposal_v2.widget.dialog.EBTBottomListDialog;
import com.ebt.m.commons.utils.Logger;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import butterknife.BindView;

public class ProposalPerson extends CompatLinearLayout {

    @BindView(R.id.person_root)
    LinearLayout root;
    @BindView(R.id.person_module_name)
    RelativeLayout nameModule;
    @BindView(R.id.person_module_sex)
    RelativeLayout sexModule;
    @BindView(R.id.person_module_age)
    RelativeLayout ageModule;
    @BindView(R.id.person_name_input)
    EditText nameInput;
    @BindView(R.id.person_radio_male)
    RadioCell radioMale;
    @BindView(R.id.person_radio_female)
    RadioCell radioFemale;
    @BindView(R.id.person_age)
    TextView btnAge;
    @BindView(R.id.person_birthday)
    TextView btnBirthday;

    /**
     * 是否是被保人信息
     * true:被保人。false:投保人
     */
    private boolean mInsured = false;

    public static final int MODULE_NAME = 0;
    public static final int MODULE_SEX = 1;
    public static final int MODULE_AGE = 2;

    private static final String BirthdayFormatPattern = "yyyy/MM/dd";
    private SimpleDateFormat birthdayFormat = new SimpleDateFormat(BirthdayFormatPattern);
    private Customer customer;
    private onInfoChangedListener mInfoChangedListener;

    private Drawable drawableRightForAge;
    private Drawable drawableLeftForBirthday;

    private ConfirmDialog confirmDialog;

    public ProposalPerson(Context context) {
        super(context);
    }

    public ProposalPerson(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    private void showConfirmChangeDialog(String message, String positiveButtonText, View.OnClickListener listener) {
        if (confirmDialog == null) {
            confirmDialog = new ConfirmDialog(getContext());
        }
        if (confirmDialog.isShowing()) {
            confirmDialog.dismiss();
        }
        confirmDialog.setMessage(message);
        confirmDialog.setPositiveButton(positiveButtonText, new OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onClick(view);
                confirmDialog.dismiss();
            }
        });
        confirmDialog.show();
    }

    @Override
    protected int setContentView() {
        return R.layout.proposal_v2_person_view;
    }

    public void setInsured(boolean insured) {
        this.mInsured = insured;
    }

    @Override
    protected void onBindView() {
        initCompoundDrawables();
        RxUtils.click(btnAge, view -> chooseAge());
        RxUtils.click(btnBirthday, view -> chooseBirthday());
        initSexListener();
    }

    private void initCompoundDrawables() {
        drawableRightForAge = getDrawable(R.drawable.ic_arrow_down);
        drawableRightForAge.setBounds(0, 0, 28, 15);
        btnAge.setCompoundDrawables(null, null, drawableRightForAge, null);

        drawableLeftForBirthday = getDrawable(R.drawable.ic_birthday_choose);
        drawableLeftForBirthday.setBounds(0, 0, 42, 36);
        btnBirthday.setCompoundDrawables(drawableLeftForBirthday, null, null, null);
    }

    private void initSexListener() {
        // 默认选中男性
        radioMale.setCheck(true);
        radioFemale.setCheck(false);
        radioFemale.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!radioFemale.isChecked()) {
                    InsuredView theInsuredView = null;
                    if (mInsured) {
                        theInsuredView = correspondInsuredView;
                    } else {
                        theInsuredView = getMyselfInsuredView();//获取当前view。若关系人本人获取投保人
                    }
                    if (theInsuredView == null) {
                        radioMale.setCheck(false);
                        radioFemale.setCheck(true);
                        callChanged();
                        return;
                    }
                    InsuredView finalTheInsuredView = theInsuredView;
                    InsuredEntity insuredEntityTemp = finalTheInsuredView.getInsured();
                    insuredEntityTemp.sex = 0;//女
                    ArrayList<Object> ret = InsuredCheckUtils.checkChangeAccordWithInsuranceLimit(mInsured, finalTheInsuredView, insuredEntityTemp, InsuranceCellView.CHECK_TYPE_SEX);
                    if (!(Boolean) ret.get(0)) {
                        /*"确定要更改性别为女吗？更改后，" + ret.get(1).toString()*/
                        showConfirmChangeDialog("性别修改后可能会导致选择的险种无法计算", "更改", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                InsuranceView insuranceView = finalTheInsuredView.getCorrespondingInsuranceView();
                                ArrayList<InsuranceCellView> list = insuranceView.getInsuranceCellViews();
                                for (InsuranceCellView cellView : list) {
                                    InsuredEntity insuredEntity = InsuredCheckUtils.getApplicantAsInsuredEntity(mInsured, insuredEntityTemp, insuranceView, cellView);
                                    cellView.setInsuredEntity(insuredEntity);
                                }
                                radioMale.setCheck(false);
                                radioFemale.setCheck(true);
                                callChanged();
                            }
                        });
                    } else {
                        InsuranceView insuranceView = finalTheInsuredView.getCorrespondingInsuranceView();
                        ArrayList<InsuranceCellView> list = insuranceView.getInsuranceCellViews();
                        for (InsuranceCellView cellView : list) {
                            InsuredEntity insuredEntity = InsuredCheckUtils.getApplicantAsInsuredEntity(mInsured, insuredEntityTemp, insuranceView, cellView);
                            cellView.setInsuredEntity(insuredEntity);
                        }
                        radioMale.setCheck(false);
                        radioFemale.setCheck(true);
                        callChanged();
                    }
                }
            }
        });
        radioMale.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!radioMale.isChecked()) {

                    InsuredView theInsuredView = null;
                    if (mInsured) {
                        theInsuredView = correspondInsuredView;
                    } else {
                        theInsuredView = getMyselfInsuredView();
                    }
                    if (theInsuredView == null) {
                        radioMale.setCheck(true);
                        radioFemale.setCheck(false);
                        callChanged();
                        return;
                    }
                    InsuredView finalTheInsuredView = theInsuredView;
                    InsuredEntity insuredEntityTemp = finalTheInsuredView.getInsured();
                    insuredEntityTemp.sex = 1;//女
                    ArrayList<Object> ret = InsuredCheckUtils.checkChangeAccordWithInsuranceLimit(mInsured, finalTheInsuredView, insuredEntityTemp, InsuranceCellView.CHECK_TYPE_SEX);
                    if (!(Boolean) ret.get(0)) {
                        /*"确定要更改性别为男吗？更改后，" + ret.get(1).toString()*/
                        showConfirmChangeDialog("性别修改后可能会导致选择的险种无法计算", "更改", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                InsuranceView insuranceView = finalTheInsuredView.getCorrespondingInsuranceView();
                                ArrayList<InsuranceCellView> list = insuranceView.getInsuranceCellViews();
                                for (InsuranceCellView cellView : list) {
                                    InsuredEntity insuredEntity = InsuredCheckUtils.getApplicantAsInsuredEntity(mInsured, insuredEntityTemp, insuranceView, cellView);
                                    cellView.setInsuredEntity(insuredEntity);
                                }

                                radioMale.setCheck(true);
                                radioFemale.setCheck(false);
                                callChanged();
                            }
                        });
                    } else {
                        InsuranceView insuranceView = finalTheInsuredView.getCorrespondingInsuranceView();
                        ArrayList<InsuranceCellView> list = insuranceView.getInsuranceCellViews();
                        for (InsuranceCellView cellView : list) {
                            InsuredEntity insuredEntity = InsuredCheckUtils.getApplicantAsInsuredEntity(mInsured, insuredEntityTemp, insuranceView, cellView);
                            cellView.setInsuredEntity(insuredEntity);
                        }
                        radioMale.setCheck(true);
                        radioFemale.setCheck(false);
                        callChanged();
                    }
                }
            }
        });
    }

    private RelativeLayout getModule(int type) {
        switch (type) {
            case MODULE_NAME:
                return nameModule;
            case MODULE_SEX:
                return sexModule;
            case MODULE_AGE:
                return ageModule;
        }
        return null;
    }

    private void chooseAge() {
        if (getFragmentManager() == null) {
            Logger.i("FragmentManager is null");
        }
        int defaultAge = getAge();
        PickerHelper.pickAge(getFragmentManager(), mInsured, defaultAge, new EBTBottomListDialog.OnSingleCheckListener() {
            @Override
            public void onSingleCheck(int position, String value) {
                //InsuredV
                int _value = Integer.parseInt(value.replace("岁", ""));
                if (defaultAge != _value) {
                    InsuredView theInsuredView = null;
                    if (mInsured) {
                        //第一被保人
                        theInsuredView = correspondInsuredView;
                    } else {
                        //不是insured，代表着这个view是投保人 ApplicantView
                        //1.需要循环遍历找到是否有关系为本人的view
                        theInsuredView = getMyselfInsuredView();
                    }
                    if (theInsuredView == null) {
                        //更新豁免险等
                        customer.setIsConfirm(0);
                        setAgeWithBirthdayReset(_value);
                        callChanged();
                        return;
                    }
                    InsuredView finalTheInsuredView = theInsuredView;
                    InsuredEntity insuredEntityTemp = finalTheInsuredView.getInsured();
                    insuredEntityTemp.birthday = null;
                    insuredEntityTemp.age = _value;
                    ArrayList<Object> ret = InsuredCheckUtils.checkChangeAccordWithInsuranceLimit(mInsured, finalTheInsuredView, insuredEntityTemp, InsuranceCellView.CHECK_TYPE_AGE);
                    if (!(Boolean) ret.get(0)) {
                        showConfirmChangeDialog("年龄修改后可能会导致选择的险种无法计算", "更改", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                InsuranceView insuranceView = finalTheInsuredView.getCorrespondingInsuranceView();
                                ArrayList<InsuranceCellView> list = insuranceView.getInsuranceCellViews();
                                for (InsuranceCellView cellView : list) {
                                    InsuredEntity insuredEntity = InsuredCheckUtils.getApplicantAsInsuredEntity(mInsured, insuredEntityTemp, insuranceView, cellView);
                                    cellView.setInsuredEntity(insuredEntity);
                                }
                                customer.setIsConfirm(0);
                                setAgeWithBirthdayReset(_value);
                                callChanged();
                            }
                        });
                    } else {
                        InsuranceView insuranceView = finalTheInsuredView.getCorrespondingInsuranceView();
                        ArrayList<InsuranceCellView> list = insuranceView.getInsuranceCellViews();
                        for (InsuranceCellView cellView : list) {
                            InsuredEntity insuredEntity = InsuredCheckUtils.getApplicantAsInsuredEntity(mInsured, insuredEntityTemp, insuranceView, cellView);
                            cellView.setInsuredEntity(insuredEntity);
                        }

                        customer.setIsConfirm(0);
                        setAgeWithBirthdayReset(_value);
                        callChanged();
                    }
                }
            }
        }, getExceptedAgeIndex());
    }

    private InsuredView getMyselfInsuredView() {
        //第一被保人
        if (correspondInsuredView != null) {
            int relation = correspondInsuredView.getRelation();
            if (relation == 0) {//本人
                return correspondInsuredView;
            }
        }
        //获取多被保人的其它InsuredView
        if (getContext() instanceof MakeProposalActivity) {
            List<InsuredView> insuredViews = ((MakeProposalActivity) getContext()).getMoreInsuredViews();
            for (InsuredView view : insuredViews) {
                if (view != null && view.getRelation() == 0) {
                    return view;
                }
            }
        }
        return null;
    }

    public ArrayList<Integer> getExceptedAgeIndex() {
        ArrayList<Integer> ret = new ArrayList<>();
        if (businessConfig == null
                || businessConfig.proposal_other_insured == null
                || businessConfig.proposal_other_insured.age == null
                || businessConfig.proposal_other_insured.age.range == null) {
            return ret;
        }
        List<String> range = businessConfig.proposal_other_insured.age.range;
        if (range.size() != 2) {
            return ret;
        }

        try {
            for (int i = 0; i < 121; i++) {
                ret.add(i);
            }
            ArrayList<Integer> ret2 = new ArrayList<>();
            float xf = Float.valueOf(range.get(0));
            float yf = Float.valueOf(range.get(1));
            int x = (int) xf;
            int y = (int) yf;
            int min = x < y ? x : y;
            int max = x > y ? x : y;
            for (int i = 0; i < min; i++) {
                ret2.add(i);
            }
            for (int i = max + 1; i < 120; i++) {
                ret2.add(i);
            }
            ret.clear();
            ret.addAll(ret2);
        } catch (Exception e) {
            e.printStackTrace();
            ret.clear();
        }
        return ret;
    }

    private void chooseBirthday() {
        int[] birthdayExists = getBirthday();
        int _year = DateUtils.thisYear() - getAge();
        int _month = 0;
        int _day = 1;
        if (birthdayExists != null && birthdayExists.length == 3) {
            _year = birthdayExists[0];
            _month = birthdayExists[1] - 1;
            _day = birthdayExists[2];
        }
        PickerHelper.chooseBirthday(getViewContext(), _year, _month, _day, (view, year, month, dayOfMonth) -> {
            boolean isDateOutpace = DateUtils.isDateOutpace(year, month, dayOfMonth);
            if (isDateOutpace) { /* 超过今天的生日无效*/
                return;
            }
            int selectedAge = DateUtils.getCalculatedAgeByBirthday(year, month, dayOfMonth);
            if (!mInsured && (selectedAge < Dictionary.APPLICANT_MIN_AGE || selectedAge > Dictionary.MAX_AGE))
                return;

            InsuredView theInsuredView = null;
            if (mInsured) {
                theInsuredView = correspondInsuredView;
            } else {
                theInsuredView = getMyselfInsuredView();
            }
            if (theInsuredView == null) {
                int[] birthdayArr = getBirthday();
                setBirthdayWithAge(year, month, dayOfMonth);
                if (birthdayArr == null || birthdayArr.length < 3) {
                    callChanged();
                } else {
                    if (birthdayArr[0] != year || birthdayArr[1] != month || birthdayArr[2] != dayOfMonth) {
                        callChanged();
                    }
                }
                customer.setIsConfirm(1);
                return;
            }
            InsuredView finalTheInsuredView = theInsuredView;

            Calendar c = Calendar.getInstance();
            c.set(year, month, dayOfMonth);
            String birthday = birthdayFormat.format(c.getTime());

            InsuredEntity insuredEntityTemp = finalTheInsuredView.getInsured();
            insuredEntityTemp.birthday = birthday;
            insuredEntityTemp.age = DateUtils.getAgeByActualBirthdayWithMonthOriginal(c.getTime());
            ArrayList<Object> ret = InsuredCheckUtils.checkChangeAccordWithInsuranceLimit(mInsured, finalTheInsuredView, insuredEntityTemp, InsuranceCellView.CHECK_TYPE_AGE);
            if (!(Boolean) ret.get(0)) {
                showConfirmChangeDialog("确定要更改生日吗？更改后，" + ret.get(1).toString(), "更改", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        InsuranceView insuranceView = finalTheInsuredView.getCorrespondingInsuranceView();
                        ArrayList<InsuranceCellView> list = insuranceView.getInsuranceCellViews();
                        for (InsuranceCellView cellView : list) {
                            InsuredEntity insuredEntity = InsuredCheckUtils.getApplicantAsInsuredEntity(mInsured, insuredEntityTemp, insuranceView, cellView);
                            cellView.setInsuredEntity(insuredEntity);
                        }

                        int[] birthdayArr = getBirthday();
                        setBirthdayWithAge(year, month, dayOfMonth);
                        if (birthdayArr == null || birthdayArr.length < 3) {
                            callChanged();
                        } else {
                            if (birthdayArr[0] != year || birthdayArr[1] != month || birthdayArr[2] != dayOfMonth) {
                                callChanged();
                            }
                        }
                        customer.setIsConfirm(1);
                    }
                });
            } else {
                InsuranceView insuranceView = finalTheInsuredView.getCorrespondingInsuranceView();
                ArrayList<InsuranceCellView> list = insuranceView.getInsuranceCellViews();
                for (InsuranceCellView cellView : list) {
                    InsuredEntity insuredEntity = InsuredCheckUtils.getApplicantAsInsuredEntity(mInsured, insuredEntityTemp, insuranceView, cellView);
                    cellView.setInsuredEntity(insuredEntity);
                }

                int[] birthdayArr = getBirthday();
                setBirthdayWithAge(year, month, dayOfMonth);
                if (birthdayArr == null || birthdayArr.length < 3) {
                    callChanged();
                } else {
                    if (birthdayArr[0] != year || birthdayArr[1] != month || birthdayArr[2] != dayOfMonth) {
                        callChanged();
                    }
                }
                customer.setIsConfirm(1);
            }
        });
    }





    public ArrayList<Object> checkChangeAccordWithInsuranceLimit(InsuredEntity insuredEntity) {
        boolean retCheckBoolean = true;
        StringBuilder retCheckString = new StringBuilder();
        ArrayList<Object> ret = new ArrayList<>();
        if (correspondInsuredView != null) {
            InsuranceView parentInsuranceView = correspondInsuredView.getCorrespondingInsuranceView();
            if (parentInsuranceView != null) {
                ArrayList<InsuranceCellView> cellViews = parentInsuranceView.getInsuranceCellViews();
                for (InsuranceCellView cellView : cellViews) {
                    ArrayList<Object> retCellCheck = cellView.checkIfMatchCondition(insuredEntity);
                    if (!(Boolean) retCellCheck.get(0)) {
                        retCheckBoolean = false;
                        retCheckString.append(cellView.getData().getDisplayName());
                        retCheckString.append(" ");
                        retCheckString.append(retCellCheck.get(1));
                    }
                }
            }
        }
        ret.add(retCheckBoolean);
        ret.add(retCheckString.toString());
        return ret;
    }

    private void callChanged() {
        if (mInfoChangedListener != null) {
            mInfoChangedListener.onInfoChanged();
        }
    }

    /********************************************************/

    /**
     * 显示该模块
     */
    public void show() {
        root.setVisibility(VISIBLE);
    }

    /**
     * 隐藏该模块
     */
    public void hide() {
        root.setVisibility(GONE);
    }

    /**
     * 显示指定模块
     *
     * @param moduleFlag
     */
    public void showModule(int moduleFlag) {
        RelativeLayout module = getModule(moduleFlag);
        if (module != null) {
            module.setVisibility(VISIBLE);
        }
    }

    /**
     * 隐藏指定模块
     *
     * @param moduleFlag
     */
    public void hideModule(int moduleFlag) {
        RelativeLayout module = getModule(moduleFlag);
        if (module != null) {
            module.setVisibility(GONE);
        }
    }

    /**
     * 设置姓名
     *
     * @param name
     */
    private void setName(String name) {
        nameInput.setText(name);
    }

    /**
     * 获取姓名
     *
     * @return
     */
    public String getName() {
        return nameInput.getText().toString().trim();
    }

    /**
     * 设置姓名
     *
     * @param age
     */
    public void setAgeOnly(int age) {
        if (age >= 0) {
            btnAge.setText(age + "岁");
        } else {
            btnAge.setText(Constant.DEFAULT_AGE + "岁");
        }
    }

    /**
     * 设置姓名，同时清空生日
     *
     * @param age
     */
    public void setAgeWithBirthdayReset(int age) {
        if (age >= 0) {
            btnAge.setText(age + "岁");
        } else {
            btnAge.setText(Constant.DEFAULT_AGE + "岁");
        }
        setNullBirthday();
    }

    /**
     * 获取姓名
     *
     * @return
     */
    public int getAge() {
        String ageString = btnAge.getText().toString().trim();
        if (ageString == null || "".equals(ageString) || "--".equals(ageString)) {
            return Constant.DEFAULT_AGE;
        }
        return Integer.parseInt(ageString.replace("岁", ""));
    }

    /**
     * 只设置生日
     *
     * @param year
     * @param month
     * @param day
     */
    public void setBirthdayOnly(int year, int month, int day) {
        Calendar c = Calendar.getInstance();
        c.set(year, month, day);
        String birthday = birthdayFormat.format(c.getTime());
        btnBirthday.setText(birthday);
        btnBirthday.setCompoundDrawables(null, null, null, null);
        btnBirthday.setTextColor(getColor(R.color.PrimaryContentColor));
    }

    /**
     * 设置生日,联动设置年龄
     *
     * @param year
     * @param month
     * @param day
     */
    public void setBirthdayWithAge(int year, int month, int day) {
        Calendar c = Calendar.getInstance();
        c.set(year, month, day);
        String birthday = birthdayFormat.format(c.getTime());
        btnBirthday.setText(birthday);
        btnBirthday.setCompoundDrawables(null, null, null, null);
        btnBirthday.setTextColor(getColor(R.color.PrimaryContentColor));
        // 修改生日时，联动修改年龄
        setAgeOnly(DateUtils.getCalculatedAgeByBirthday(year, month, day));
    }

    /**
     * 生日重置
     */
    private void setNullBirthday() {
        btnBirthday.setText("选择生日");
        btnBirthday.setCompoundDrawables(drawableLeftForBirthday, null, null, null);
        btnBirthday.setTextColor(getColor(R.color.PrimaryContentColorLight));
    }

    /**
     * 获取生日
     *
     * @return
     */
    public int[] getBirthday() {
        String birthday = btnBirthday.getText().toString().trim();
        final String split = "/";
        if (!VerificationUtils.isBirthday(birthday, split)) {
            return null;
        }
        return ArrayUtils.toBirthdayArray(birthday, split);
    }

    /**
     * 获取性别
     *
     * @return
     */
    public int getSex() {
        if (radioMale.isChecked()) {
            return Constant.SEX_MALE;
        }
        if (radioFemale.isChecked()) {
            return Constant.SEX_FEMALE;
        }
        return Constant.SEX_MALE;
    }

    /**
     * 设置性别
     *
     * @param sex
     */
    public void setSex(int sex) {
        if (sex == 1) {
            radioMale.setCheck(true);
            radioFemale.setCheck(false);
            return;
        }
        if (sex == 0) {
            radioFemale.setCheck(true);
            radioMale.setCheck(false);
            return;
        }
        radioMale.setCheck(true); // 默认选择'男'
    }

    /**
     * 绑定数据
     *
     * @param customer
     */
    public void setCustomer(Customer customer) {
        if (customer == null) {
            return;
        }
        setName(customer.getName());
        setSex(customer.getSex());
        setAgeOnly(customer.getAge());

        Date birthday = customer.getBirthday();
        DateTime birthdayDT = DateUtils.toDateTime(birthday);
        if (birthdayDT != null) {
            setBirthdayOnly(birthdayDT.year, birthdayDT.month, birthdayDT.day);
        } else {
            setNullBirthday();
        }
        Customer customerCopy = new Customer();
        customerCopy.setCustomerId(customer.getCustomerId());
        customerCopy.setName(customer.getName());
        customerCopy.setAge(customer.getAge());
        customerCopy.setBirthday(customer.getBirthday());
        customerCopy.setCareerCategory(customer.getCareerCategory());
        customerCopy.setRelationWith(customer.getRelationWith());
        customerCopy.setSex(customer.getSex());
        customer.setIsConfirm(customer.getIsConfirm());
        this.customer = customerCopy;
    }

    /**
     * 获取数据
     *
     * @return
     */
    public Customer getCustomer() {
        if (customer == null) {
            customer = new Customer();
        }
        customer.setName(getName());
        customer.setSex(getSex());
        customer.setAge(getAge());
        int[] birthdayArray = getBirthday();
        if (birthdayArray != null && birthdayArray.length == 3) {
            customer.setBirthday(DateUtils.toDate(birthdayArray[0], birthdayArray[1] - 1, birthdayArray[2]));
        } else {
            customer.setBirthday(null);
        }
        return customer;
    }

    /**
     * 添加信息是否改变监听
     * <p>
     * 1/ 性别、年龄、生日变更时调用
     * 2/ 适用投保人是否保存到客户列表显现
     *
     * @param listener
     */
    public void setInfoChangedListener(onInfoChangedListener listener) {
        mInfoChangedListener = listener;
    }

    public interface onInfoChangedListener {
        void onInfoChanged();
    }

    private BusinessConfig businessConfig;

    public void setBusinessConfig(BusinessConfig config) {
        businessConfig = config;
    }

    public BusinessConfig getBusinessConfig() {
        return businessConfig;
    }

    private InsuredView correspondInsuredView;

    public void setCorrespondInsuredView(InsuredView insuredView) {
        correspondInsuredView = insuredView;
    }
}
